using System;
using System.Collections.Generic;
using Csla;
using System.Data;
using ENT.GP.Datos.MysqlHelper;

namespace ENT.GP.Core.Estadisticas
{
    [Serializable]
    public class OpcionVariables :
      ReadOnlyListBase<OpcionVariables, OpcionVariable>
    {
        #region Authorization Rules

        private static void AddObjectAuthorizationRules()
        {
            // TODO: add authorization rules
            //AuthorizationRules.AllowGet(typeof(OpcionVariables), "Role");
        }

        #endregion

        #region Factory Methods

        public static OpcionVariables GetOpcionVariables()
        {
            return DataPortal.Fetch<OpcionVariables>();
        }

        private OpcionVariables()
        { /* require use of factory methods */ }

        #endregion


        #region Data Access

        private void DataPortal_Fetch()
        {
            RaiseListChangedEvents = false;
            IsReadOnly = false;

            HelperMySql objhm = HelperMySql.ObtenerConexion("");
            foreach (DataRow items in objhm.EjecutarStoreProcedure(null, "Listar_Campos_Consulta").Tables[0].Rows)
            {
                this.Add(OpcionVariable.GetOpcionVariable(items));
            }

            IsReadOnly = true;
            RaiseListChangedEvents = true;
        }

        #endregion
    }


    [Serializable]
    public class OpcionVariable : ReadOnlyBase<OpcionVariable>
    {
        #region Business Methods

        public int Id { get; set; }
        public string Codigo { get; set; }
        public string Campo { get; set; }
        public string Descripcion { get; set; }

        #endregion

        #region Factory Methods

        internal static OpcionVariable GetOpcionVariable(DataRow childData)
        {
            return DataPortal.FetchChild<OpcionVariable>(childData);
        }

        private OpcionVariable()
        { /* require use of factory methods */ }

        #endregion

        #region Data Access

        private void Child_Fetch(DataRow childData)
        {
            this.Id = Convert.ToInt32(childData[0].ToString());
            this.Codigo = childData[1].ToString();
            this.Campo = childData[2].ToString();
            this.Descripcion = childData[3].ToString();
        }

        #endregion
    }
}
